package properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.nio.charset.Charset;
import java.util.Properties;

/**
 * @author liufei
 * @date 2021/8/9 10:47
 */
public class BaseProperties {

    protected static final Logger logger = LoggerFactory.getLogger(BaseProperties.class);

    protected static Properties readProperties(String propertiesFileName) {
        Properties properties = new Properties();
        try {
            File file = new File("./" + propertiesFileName);
            InputStreamReader inputStreamReader;
            if (!file.exists()) {
                inputStreamReader = new InputStreamReader(
                        BaseProperties.class.getResourceAsStream("/" + propertiesFileName),
                        Charset.forName("UTF8"));
            } else {
                InputStream resourceAsStream = new FileInputStream("./" + propertiesFileName);
                inputStreamReader = new InputStreamReader(
                        resourceAsStream,
                        Charset.forName("UTF8"));
            }
            properties.load(inputStreamReader);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return properties;
    }

}
